﻿using Enter.Admin.Dtoes;
using FluentValidation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Enter.Admin.Configs.Validator
{
    public class UserLoginModelValidator : AbstractValidator<UserLoginModel>
	{
		// ModelState.IsValid == true 验证通过;
		// <input asp-for="UserName" /> <span asp-validation-for="UserName"></span>
		/*
		 手动验证
		public ActionResult DoSomething() {
		  var customer = new Customer();
		  var validator = new CustomerValidator();
		  var results = validator.Validate(customer);

		  results.AddToModelState(ModelState, null);
		  return View();
		}

		验证拦截器
		IValidatorInterceptor	
		 */
		public UserLoginModelValidator()
		{
			RuleFor(x => x.UserName).NotNull().WithMessage("用户名不能为空").MinimumLength(2).WithMessage("用户名最少2个长度");
			RuleFor(x => x.Password).NotNull().WithMessage("密码不能为空").MinimumLength(6).WithMessage("密码最少6个长度");
		}
	}
}
